package com.aixin.project.handler;

import com.aixin.project.data.CourseOrder;
import com.aixin.project.db.CourseOrderDao;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Sufeng
 * Date: 12-4-23
 * Time: 上午11:17
 * To change this template use File | Settings | File Templates.
 */
public class CourseOrderHandler {
    public static CourseOrder find(long coid){
        return CourseOrderDao.find(coid);
    }
    
    public static CourseOrder find(long cid,long uid){
    	return  CourseOrderDao.find(cid, uid);
 
    }

    public static long create(CourseOrder order){
        return CourseOrderDao.insert(order);
    }
    
    public static int update(CourseOrder order){
        if(order != null && order.getStatus()==0){
            return CourseOrderDao.update(order);
        }
        return -1;
    }
    
    public static int create(long cid,long uid ,CourseOrder order){
    	CourseOrder csorder=CourseOrderDao.find(cid, uid);
    	if(csorder!=null){
    		if(csorder.getStatus()==0)
    		   return CourseOrderDao.update(order);
    		else
    		   return (int) CourseOrderDao.insert(order);
    	}else
    	 return (int) CourseOrderDao.insert(order);
    }

    public static List<CourseOrder> listPagenation(int page,int psize,int status){
        return CourseOrderDao.listPagenation(page,psize,status);
    }
    public static long count(int status){
        return CourseOrderDao.count(status);
    }
    
    public static int pointCount(long uid, long courseid){
        return CourseOrderDao.pointCount(uid,courseid);
    }
}
